﻿@{
    Layout = null;
}
@using CNKI.TPI.Web.Admin.Model;
@using CNKI.TPI.Web.Base
@Scripts.Render("~/bundles/jqueryform")
<script>
    //全选
    function subjectcheckall(e) {
        if ($(e).attr("checked") == "checked") {
            $(".checkboxsubject input[type='checkbox']").each(function () {
                $(this).attr("checked", "checked");
            })
        }
        else {
            $(".checkboxsubject input[type='checkbox']").each(function () {
                $(this).removeAttr("checked", "checked");
            })
        }
    }
    $(".checkboxsubject input[type='checkbox']").click(function () {
        //循环判断列表中的checkbox，如果全部选中则全选框呈勾选状态
        var m = 0;
        if ($(this).attr("checked") != "checked") {
            $("input.subjectall").removeAttr("checked", "checked");
        }
        else {
            $(".checkboxsubject input[type='checkbox']").each(function () {
                if ($(this).attr("checked") != "checked") {
                    m = 1;
                }
            })
            if (m == 1) {
                $("input.subjectall").removeAttr("checked", "checked");
            }
            else {
                $("input.subjectall").attr("checked", "checked");
            }
        }

    })
    //删除 多选
    function delsubjectlist() {
        var ckbs = $(".checkboxsubject input[type='checkbox']:checked");
        if (ckbs.size() == 0) {
            messageAlert("请选择要删除的记录！");
            return;
        }
        confirmDialog('确定要删除吗?', function () {
            var checkedstr = [];
            ckbs.each(function () {
                checkedstr.push($(this).val());
            })
            var delurl = "@Html.Raw(Url.Action("DelSubject", "Admin_Topic"))";
            var data = { "sysidstr": checkedstr.toString() };
            dealdata(delurl, data);
        })

    }
    //添加专题
    function addsubject() {
        $("#sysid").val(0);
        $("#code").val("");
        $("#status").val(1);
        $(".talkDiv-title span").html("新建专题库");
        $("#subjectname").val("");
        $("#subjectpage").val("TopicSubjectIndex");
        $("#topiclogo").attr('src', '');
        $("#topiclogoDiv").append("<input type=\"file\" name=\"uploadfile\" id=\"uploadfile\" size=\"60\" />");
        showsubject();
    }
    //编辑
    function modifysubject(sysid, name, code, staus, page, pic, topicdb, copyright, domain) {

        $("#sysid").val(sysid);
        $("#code").val(code);
        $("#topicdb").val(topicdb);
        $("#copyright").val(copyright);
        $("#status").val(staus);
        $("#subjectname").val(name);
        $("#domain").val(domain);
        if (pic != "")
        {
            $("#topiclogoDiv").append("<img name=\"topiclogo\" id=\"topiclogo\" style=\"height:100px;width:330px\" src="+pic+" />");
        }
        $("#topiclogoDiv").append("<input type=\"file\" name=\"uploadfile\" id=\"uploadfile\" size=\"60\" />");
        $("#subjectpage").val(page);
        $("#topiclogo").attr('src', pic);
        $(".talkDiv-title span").html("编辑专题库");
        showsubject();
    }
    //删除
    function delsubject(sysid) {
        var delurl = "@Html.Raw(Url.Action("DelSubject", "Admin_Topic"))";
        var data = { "sysidstr": sysid };
        confirmDialog('确定要删除吗?', function () {
            dealdata(delurl, data);
        })
    }
    function closesubject() {
        $("#topiclogo").remove();
        $("#uploadfile").remove();
        $(".talkDivBg").hide();
        $(".subjectform").hide();
    }
    function showsubject() {

        $(".talkDivBg").show();
        $(".subjectform").show();
    }
    //调用controll
    function dealdata(urlstr, datastr) {
        $.ajax({
            type: "POST",
            url: urlstr,
            data: datastr,
            success: function (m) {
                if (m == "True") {
                    messageAlert("操作成功！");
                    ajaxLoad("initload", '@Html.Raw(Url.Action("SubjectHomePage", "Admin_Topic"))');
                }
                else {
                    messageAlert("操作失败！");
                }
            },
            error: function (e)
            { }
        })
    }
    function savesubject() {
        var subjectname = $("#subjectname").val();
        if ($.trim(subjectname) == "") {
            messageAlert("请输入专题库名称！");
            return;
        }
        else if (!regtext(subjectname)) {
            messageAlert("不允许输入特殊字符！");
            return;
        }
        var domain = $("#domain").val();
        if ($.trim(domain) == "") {
            messageAlert("请输入绑定的域名！");
            return;
        }
        else if (!regtext(domain)) {
            messageAlert("不允许输入特殊字符！");
            return;
        }
        var topicdb = $("#topicdb").val();
        if (topicdb == 0) {
            messageAlert("请选择数据源！");
            return;
        }
        var page = $("#subjectpage").val();
        if ($.trim(page) == "") {
            messageAlert("请输入页面路径！");
            return;
        }
        else if (!regtext(page)) {
            messageAlert("不允许输入特殊字符！");
            return;
        }
        $.ajax({
            type: "GET",
            url: "@Html.Raw(Url.Action("IsExitSubject", "Admin_Topic"))?name=" + subjectname + "&sysid=" + $("#sysid").val(),
            success: function (obj) {
                //;
                if (obj == "True") {
                    messageAlert("该专题库名称已经存在！");
                }
                else {
                    savedata();
                }
            },
            error: function (e) {
                //;
            }
        })

    }
    function savedata() {
        @*var subjectname = $("#subjectname").val();
        var page = $("#subjectpage").val();
        var pic = $("#subjectpic").val();
        var insertdata = {
            "TopicName": subjectname, "TopicCode": $("#code").val(), "TopicStatus": $("#status").val(),
            "SysID": $("#sysid").val(), "TopicPage": page, "TopicPic": pic
        };
        var saveurl = "@Html.Raw(Url.Action("SaveSubject", "Admin_Topic"))";
        var savedata = { "obj": insertdata };*@
        
        $("#uploadform").ajaxSubmit(function (responseResult) {
            if (responseResult == "True") {
                messageAlert("操作成功！");
                closesubject();
                ajaxLoad("initload", '@Html.Raw(Url.Action("SubjectHomePage", "Admin_Topic"))');
            }
            else {
                messageAlert("操作失败！");
            }
        });

        @*$.ajax({
            type: "POST",
            url: saveurl,
            data: $('#uploadform').serialize(),
            async: false,
            success: function (m) {
                if (m == "True") {
                    messageAlert("操作成功！");
                    closesubject();
                    ajaxLoad("initload", '@Html.Raw(Url.Action("SubjectHomePage", "Admin_Topic"))');
                }
                else {
                    messageAlert("操作失败！");
                }
            },
            error: function (e)
            { }
        })*@
    }


    function dealchecked(checkedsub, checkedparent) {
        var m = 0;
        $(checkedsub).each(function () {
            if ($(this).attr("checked") != "checked") {  //遍历判断是否存在没有选中的记录
                m = 1;
            }
        })
        if (m == 1) {
            $(checkedparent).removeAttr("checked", "checked");
        }
        else {
            $(checkedparent).attr("checked", "checked");
        }
    }
    function setInfo(topiccode, topicname, topicdb) {
        console.log(topiccode);
        ajaxLoad('initload', "@Html.Raw(Url.Action("SubjectSetList", "Admin_Topic"))?TopicName=" + escape(topicname) + "&TopicCode=" + topiccode + "&TopicDB=" + topicdb)
    }
</script>


<table width="100%" cellspacing="0" cellpadding="0" border="0" class="table table-grey">
    <thead>
        <tr class="thead">
            <th class="tdnum">
                <input type="checkbox" class="subjectall" value="" name="" onclick="subjectcheckall(this)">序号</th>
            <th>专题库名称</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @{if (ViewBag.SubjectList != null)
          {
              int sortno = ViewBag.PageSize * (ViewBag.PageNow - 1) + 1;
              foreach (SYS_CMS_TOPIC item in ViewBag.SubjectList)
              {
                  string str = "even";
                  if (sortno % 2 == 0)
                  {
                      str = "odd";
                  }
            <tr class='@str'>
                <td class="checkboxsubject">
                    <input type="checkbox" value="@item.SYSID">@sortno</td>
                <td style="width:600px"><a class="atitle" title="@ColumnAliasHelper.GetContentNoRed(item.TopicName)">@Html.Raw(ColumnAliasHelper.SubContent(item.TopicName, 20))</a></td>
                <td class="tc">
                    <a onclick="setInfo('@item.TopicCode','@item.TopicName','@item.TopicDB')" href="javascript:void(0)">配置</a>
                    <a onclick="modifysubject('@item.SYSID','@item.TopicName','@item.TopicCode','@item.TopicStatus','@item.TopicPage','@item.TopicPic','@item.TopicDB','@item.CopyRight','@item.Domain')" href="javascript:void(0)">编辑</a>
                    <a onclick="delsubject('@item.SYSID')" href="javascript:void(0)">删除</a>
                </td>
            </tr>
                  sortno = sortno + 1;
              }
          }

        }
    </tbody>
</table>

@*//分页*@
<div class="pagenav pagenav-02">
    @*上一页*@
    @if (ViewBag.TotalPage > 0)
    {
        if (ViewBag.PageNow != 1)
        {
            int thispage = ViewBag.PageNow - 1;
        <a href="javascript:void(0);" class="page-prev" onclick="searchPageNew('@thispage')" >上一页</a>
        }
        else
        {
        <a href="javascript:return false;"  onclick="return false" class="page-prev disable">上一页</a>
        }
@*循环初始化页码*@
        foreach (string numpage in ViewBag.PageList)
        {
            if (numpage != "0")
            {
                int m = int.Parse(numpage);
                if (m == ViewBag.PageNow)
                {
        <a href="javascript:void(0);" class="active" onclick="searchPageNew('@numpage')">@numpage</a>
                    
                }
                else
                {
        <a href="javascript:void(0);" onclick="searchPageNew('@numpage')">@numpage</a>
                }

            }
            else
            {
        <i class="iconfont icon-dian2"></i>
            }

        }
@*下一页*@
        if (ViewBag.TotalPage > 0 && ViewBag.PageNow != ViewBag.TotalPage)
        {
            int nextpage = ViewBag.PageNow + 1;
        <a href="javascript:void(0);" class="page-next" onclick="searchPageNew('@nextpage')" >下一页</a>
        }
        else
        {
        <a href="javascript:return false;"  onclick="return false" class="page-prev disable">下一页</a>
        }
    }
    @if (@ViewBag.Count == 0)
    {
        <label>暂无数据！</label>
        
    }
    else
    {
          
        <label>共 </label>
        <label>@ViewBag.Count </label>
        <label>条数据 </label>
    }
</div>
<div class='posr' style="padding-bottom: 20px">

    <a class="btn btn-m btn-submit btn-defa-f" href="javascript:void(0);" onclick="addsubject()">添加</a>
    <a class="btn btn-m btn-submit btn-defa-f" href="javascript:void(0);" onclick="delsubjectlist()">删除</a>
</div>


<!--talkDiv弹出层(不带图片，宽550)-->
<!--透明背景-->
<div class="talkDivBg" style="display: none;">
    <div class="talkDiv talkDivTr talkW-550 form-h subjectform" style='margin-top: -135px; display: none'>
        <div class="talkDiv-title">
            <span>新建专题库</span>
            <a class="icon icon-close" title="关闭" onclick="closesubject()" href="javascript:void(0);"><i class="iconfont icon-error3"></i></a>
        </div>
        <div class="talkDiv-body talkDiv-body1">
            <form name="uploadform" id="uploadform" action="@Html.Raw(Url.Action("SaveSubject", "Admin_Topic"))" method="post" enctype="multipart/form-data" >
                <div class="f-gp">
                    <div class="f-lb" style="width:100px">
                        <label class="f-label">专题库名称：</label>
                    </div>
                    <div class="f-ct">
                        <input type="text" value="" class="f-text span5" id="subjectname" maxlength="20" name="subjectname">
                        <span class="f-label-re">*</span>
                    </div>
                </div>
                <div class="f-gp">
                    <div class="f-lb" style="width:100px">
                        <label class="f-label">数据源：</label>
                    </div>
                    <div class="f-ct">
                        <select id="topicdb" name="topicdb" class="f-select span3">
                            <option value="0">请选择数据源</option>
                            @{
                                if (ViewBag.DBList != null)
                                {
                                    foreach (SYS_CMS_TOPIC_DBCONFIG item in ViewBag.DBList)
                                    {
                                        <option value="@item.SYSID">@item.Name</option>
                                    }

                                }
                            }
                        </select>
                        <span class="f-label-re">*</span>
                    </div>
                </div>
                <div class="f-gp">
                    <div class="f-lb" style="width:100px">
                        <label class="f-label">版权信息：</label>
                    </div>
                    <div class="f-ct">
                        <input type="text" value="" class="f-text span5" id="copyright" maxlength="100" name="copyright">
                        <span class="f-label-re">*</span>
                    </div>
                </div>
                <div class="f-gp">
                    <div class="f-lb" style="width:100px">
                        <label class="f-label">域名绑定：</label>
                    </div>
                    <div class="f-ct">
                        <input type="text" value="" class="f-text span5" id="domain" maxlength="100" name="domain">
                        <span class="f-label-re">*</span>
                    </div>
                </div>
                <div class="f-gp">
                    <div class="f-lb" style="width:100px">
                        <label class="f-label">模板：</label>
                    </div>
                    <div class="f-ct">
                        <select id="subjectpage" name="subjectpage" class="f-select span3">
                            <option value="Default">默认</option>
                            <option value="Zyyj">中亚及俄罗斯研究</option>
                        </select>
                        @*<input type="text" value="" class="f-text span5" id="subjectpage" maxlength="60" name="subjectpage">*@
                        <span class="f-label-re">*</span>
                    </div>
                </div>
                <div class="f-gp">
                    <div class="f-lb" style="width:100px">
                        <label class="f-label">标题图片：</label>
                    </div>
                    <div id="topiclogoDiv" class="f-ct">
                        @*<img name="topiclogo" id="topiclogo" style="height:100px;width:330px" src="" />*@
                        @*<input type="file" name="uploadfile" id="uploadfile" size="60" />*@
                        @*<input type="text" value="" class="f-text span5" id="subjectpic" maxlength="60">*@
                    </div>
                </div>
                <input type="hidden" id="sysid" name="sysid" value="0" />
                <input type="hidden" id="code" name="code" value="" />
                <input type="hidden" id="status" name="status" value="1" />
            </form>
                <div class="f-gp">
                    <div class="f-lb">
                        <label class="f-label"></label>
                    </div>
                    <div class="f-ct" style="margin-left: 150px">
                        <a href="javascript:void(0);" class="btn btn-m btn-prim-f btn-submit" onclick="savesubject()">保存</a>
                        &#12288;<a href="javascript:void(0);" class="btn btn-m btn-submit btn-defa-f" onclick="closesubject()">取消</a>
                    </div>
                </div>

</div>
    </div>
</div>
